package com.yunwushanhe.document.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/*这个类是来处理实体类中的@TableField(fill = FieldFill.INSERT)与@TableField(fill = FieldFill.INSERT_UPDATE)这两个注解的*/
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert start ... ");
        this.setFieldValByName("gmtCreate",new Date(),metaObject);
        this.setFieldValByName("gmtUpdate",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("update start ... ");
        this.setFieldValByName("gmtUpdate",new Date(),metaObject);
    }
}
